Skip to content

Support lossless float narrowing in Widen and BtrBlocks - #11901

Open
lwwmanning wants to merge 7 commits into
developfrom
wm/float-widen-array
Open

lwwmanning wants to merge 7 commits into
developfrom
wm/float-widen-array

Conversation

@lwwmanning

@lwwmanning lwwmanning commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

This adds float children to the Widen array, and a BtrBlocks scheme, FloatWidenScheme, that stores float columns narrower when that loses no bits. Integer and decimal Widen arrays keep their behavior and their wire bytes.

On develop, Widen holds only integer and decimal children, so an f64 column of exact f32 values stays at full width. With this PR, WidenArray::encode_float narrows f64 to f32 or f16, or f32 to f16, when every valid value widens back bit for bit. -0.0 stays distinct from +0.0, and any NaN other than the positive canonical quiet NaN keeps the column wide.

Comparisons with an exact constant or another float Widen, cast, fill_null, zip, and order aggregates such as MinMax run on the narrow child. Float arithmetic and Sum widen first, because their rounding depends on the width.

The PR also changes three other things. A take with more indices than values now declines, so Dict widens its values once, for integer and decimal Widen too. The widen::encode module and CompressorContext::with_sampling become public, for the scheme. The CUDA Widen kernel decodes a float Widen on the host.

The scheme runs only when the target edition allows vortex.widen, so default writes do not change, and CUDA writers skip it. In the author's run on 45 benchmark datasets, it made preview2026.11.0 files 11.4% smaller in total, mostly from f32 embeddings stored as f64.

Wire format change: vortex.widen now stores a float child as its PType under tag 1, with no new ID or tag. vortex.widen belongs to preview2026.11.0, which has no min_library_version yet, so its members can still change. But releases 0.94.0 and 0.95.0 include that edition, and their readers fail on a float Widen with "Widen child metadata does not match the parent dtype".

Authored with AI assistance.

@lwwmanning lwwmanning added the changelog/feature A new feature label Nov 24, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T00:27:20.368799Z 1b8af79 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

The lossless check and the compare pushdown hold up. I traced signed zeros, subnormals, constants beyond the narrow range, NaN and null constants, and the rejection of the v1 tag, and the frozen vortex.widen output for integers and decimals is unchanged.

There is one bug. The CUDA WidenExecutor was not updated, so a float child panics on the GPU path (inline).

Beyond that, the PR is larger than a first version needs. The constant folding for values that fall between two narrow floats, a dead float arm in constant_fits_values, an encode_float that only tests call, and a second copy of the aggregate allowlist can all go or move to follow-ups. That would leave a PR that stores floats narrow and pushes down only what fits exactly.

@devin-ai-integration
devin-ai-integration Bot force-pushed the wm/float-widen-array branch 2 times, most recently from b692593 to 83b1715 Compare November 24, 2026 11:35
devin-ai-integration[bot]

This comment was marked as resolved.

@codspeed

codspeed Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

Warning

vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 2225 untouched benchmarks
⏩ 101 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation encode_primitives[u8, (2000, 2)] 92.5 µs 119.1 µs -22.35%
⚡ CPU Simulation take_many_indices 618.7 µs 429.3 µs +44.14%
⚡ CPU Simulation varbinview_large 152.5 µs 134.8 µs +13.16%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing wm/float-widen-array (8fd28d7) with develop (c6990e0)

Open in CodSpeed

Footnotes

  1. 101 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@vortex-roborev-bot

vortex-roborev-bot Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

roborev: Combined Review (38476e3)

Verdict: Changes require fixes for 1 finding.

Low

  • vortex-btrblocks/src/schemes/float/widen.rs:208-235: FloatWidenScheme::compress runs the full compress_encoded cascade for both F16 and F32 when an f64 column fits f16. The estimate callback has already compared these candidates, but it caches only NarrowestFloatTarget and not which candidate won. As a result, compress_with_candidates repeats the work on the full array. For these columns, compression at write time costs about twice as much.

    Fix: Cache the winning candidate's ptype from the estimate callback in ArrayAndStats and have compress narrow only to that target, falling back to trying both candidates only when no winner is cached.


Reviewers: claude-code | Synthesis: claude-code, 8s, ~$0.04 | Total: 3m11s, ~$1.54

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed the roborev findings in c83f7a1c2:

  1. Updated the constant_fits_values doc comment to match the implementation (returns None for floats).
  2. Documented the bit-exactness precondition on narrow_float_values (kept pub mod encode because vortex-btrblocks calls narrowest_float_ptype and narrow_float_values directly in Add FloatWidenScheme to BtrBlocks for lossless float narrowing #11902).
  3. Added test_float_host_fallback in vortex-cuda/src/kernel/encodings/widen/tests.rs covering WidenArray::encode_float (f32 -> f64) with -0.0, NaN, and nulls through execute_cuda.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed the updated roborev finding in 45fe86a16: added test_float_zip in vortex-functions/src/zip/widen.rs covering float Widen-vs-Widen and Widen-vs-constant (f16, f32, 0.1, and non-canonical NaN) with -0.0, canonical NaN, and nulls, asserting both stored PType and bit-exact values.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@lwwmanning
lwwmanning marked this pull request as draft November 25, 2026 02:32
@lwwmanning lwwmanning changed the title Support lossless floating-point narrowing in Widen Support lossless float narrowing in Widen and BtrBlocks Nov 26, 2026
@lwwmanning
lwwmanning marked this pull request as ready for review November 26, 2026 03:52
chatgpt-codex-connector[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

Fresh review of the rewrite at c178d007. The bit-exact fit check, the constant compare pushdown and the cast rules look correct to me, and I found no bugs. Three points:

  1. Wire format. Float children reuse tag 1 of the existing vortex.widen metadata, with no new ID, which is much simpler than the earlier vortex.widen.v2 version. But preview2026.11.0 shipped in 0.94.0 and 0.95.0, and those readers fail on a float Widen with "Widen child metadata does not match the parent dtype". The edition has no min_library_version, so the code treats it as a draft that may change. The plugin's module doc also says that a field that changes the decoded values needs a new ID. A maintainer should check that a draft edition may widen what vortex.widen means.

  2. compress_with_target compresses an f64 column that fits f16 twice, once as f16 and once as f32, and keeps the smaller. That is reasonable for the sample estimate, but compress repeats it on the full array. Could the estimate record which width won, so that compress encodes only that width?

  3. Proportion. About 1,400 of the 2,293 added lines are tests: 53 cases in tests/float.rs, 35 in tests/serde.rs, and 26 test functions in schemes/float/widen.rs. Please check whether cases that exercise the same path can merge.

Smaller notes: the take change, which declines when there are more indices than values, also applies to integer and decimal Widen. CompressorContext::with_sampling becomes public API. On the Codex signaling-NaN thread, I agree with Devin: the reader checks only the metadata, in constant time, as it does for decimal children.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed the review points in fe27362a1:

  1. Wire format: Left vortex.widen unchanged as rewritten (since preview2026.11.0 has min_library_version: None), flagging for maintainer confirmation during review.
  2. Duplicate f16/f32 compression: Added CachedBestTarget in vortex-btrblocks/src/schemes/float/widen.rs so sampled estimation caches the winning width and compress() encodes only that width on the full array.
  3. Test consolidation: Merged the duplicated float serde tests into test_widen_wire_round_trip, test_widen_wire_id_requires_permission, and test_widen_wire_rejects_invalid_child_metadata (using literal wire bytes [8, 9] / [8, 8]), and consolidated the overlapping FloatWidenScheme tests (-97 net lines).

devin-ai-integration[bot]

This comment was marked as resolved.

@robert3005 robert3005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the bit-exact claim for -0.0, NaN payloads, subnormals, and the f64 -> f32 -> f64 and f64/f32 -> f16 round trips. The fit check, the narrow compare with an exact constant, the cast rules and the order aggregates on the child are correct: the accepted values widen one-to-one and keep IEEE order. I did not repeat the points that are already open (wire format of preview2026.11.0, test proportion, pub mod encode, the take change for integer and decimal Widen).

One low-severity question, inline, about f32 subnormals and the FP mode of the reader.

/// Returns whether `value` round-trips bit-for-bit through `f32`, accepting only the positive
/// canonical quiet NaN (`f64::NAN`) among NaN bit patterns.
#[inline]
pub(in crate::arrays::widen) fn f64_fits_in_f32(value: f64) -> bool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low severity, a question more than a defect. This accepts f64 values that are subnormal in f32, for example f64::from(f32::from_bits(1)). The reader widens an f32 child in convert_values (primitive/compute/cast.rs) with as, which compiles to cvtps2pd on x86 and fcvt on aarch64. When a thread runs with DAZ (x86 MXCSR) or FZ (aarch64 FPCR) set, these instructions read a subnormal input as zero, so a value written as 1.4e-45 decodes as 0.0. A plain f64 column has no conversion on read, so it is not affected. Rust itself assumes the default FP environment, so this is only a gap between the "bit for bit" doc and a reader that changes FP flags.

If you want the guarantee to hold there too, the f32 fit check can also reject a nonzero f32 with a zero exponent field. Real f64 data rarely holds f32 subnormals, so the size cost is small. I would not apply this to f16, because f16 subnormals reach about 6e-5 and occur in real data. Otherwise, a short note in the module doc is enough.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — documented in vortex-array/src/arrays/widen/mod.rs (0cd7217c5) that bit-exact widening assumes the default IEEE-754 floating-point environment (without DAZ/FTZ flushing f32 subnormals to zero), matching Rust's own FP-mode assumption without adding an extra check to the hot f64_fits_in_f32 scan. Happy to reject f32 subnormals in f64_fits_in_f32 instead if you'd prefer that guarantee under DAZ/FTZ.

@devin-ai-integration
devin-ai-integration Bot force-pushed the wm/float-widen-array branch 2 times, most recently from 0deaca5 to dcf1772 Compare November 27, 2026 18:57
lwwmanning and others added 3 commits November 28, 2026 12:16
Extend WidenArray and its existing preview vortex.widen wire format to narrow floating-point arrays bit-exactly (f64 to f32/f16, f32 to f16) using tag 1 (ChildType::Primitive) without introducing a new array ID or protobuf tag, and add FloatWidenScheme to BtrBlocks (excluded in CUDA writer preset, with CUDA WidenExecutor staging float Widen on host).

Signed-off-by: Will Manning <will@willmanning.io>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I reviewed a220f6c with fresh eyes, and the core is correct. The fit checks compare bit patterns, so -0.0 stays distinct, and a signaling NaN fails because the narrowing cast quiets it. narrow_slice_with_mask writes zero into null slots. A compare runs on the child only when a non-NaN constant fits the child type exactly. Sum and arithmetic decline, and tag 1 keeps the integer wire bytes.

A cast from the child also matches a cast from the widened values, because widening is exact. Three points follow, most important first.

  1. narrow_float_values is public and rounds silently. pub mod encode exposes it and narrowest_float_ptype for the BtrBlocks scheme. A caller that skips the fit check gets rounded values inside a Widen and no error. The function already visits every valid value, so it can compare each widened result with its input and return an error on a mismatch. That makes the public entry point safe at little cost.

  2. FloatWidenScheme is larger than the problem needs. It has 316 lines before its tests and keeps three caches, while each other float scheme file has 97 to 142 lines in total. The scheme needs NarrowestFloatTarget and the callback that reuses it on the sample, because a sample can miss an f32-only outlier. It also needs the f16 and f32 comparison, because ALP skips f16.

    The rest looks optional. CachedFullWiden only saves compressing an array of under 3,072 rows a second time. CachedBestTarget only saves one extra candidate on f64 columns that fit f16. The finished_cascading branch seems to give the ratio that the sampled callback would also give. Unless a benchmark shows these matter, removing them would make the scheme much shorter.

  3. The tests could lean on the existing harnesses. About 1,350 of the 2,200 added lines are tests, and much of tests/float.rs hand-picks values for operations that shared suites already check. I suggest these changes:

    • Add a nullable float fixture, with -0.0, infinities and NaN, to test_conformance in tests/compute.rs. It runs the cast, filter, take, mask and consistency suites.
    • Add one Hegel test. Draw each value as either an f32 widened to f64, including subnormals and the edge values, or arbitrary f64 bits, and draw a validity. Call encode_float. Check that valid rows decode bit for bit, and that the child is narrower only when every valid value fits. Then pass the result to check_encoding_roundtrip_and_ops. The current tests compare bits by hand, so the property should too.
    • Then remove test_encode_float_f64_bit_exact_round_trip, test_float_filter_mask_slice_take and most of test_compare_f32_widen_to_f64_constants. Keep the tables for NaN and signaling NaN rejection, the constants that decline, the cast rules and the serde cases, because they pin specific contracts.

Minor: the take change, which returns None when there are more indices than values, also changes integer and decimal Widen. A measured result in the description would show what it gains.

…iden tests

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed the cleanup items in 8fd28d7f9:

  1. Checked narrow_float_values: narrow_float_values now verifies every valid value round-trips bit-for-bit (and rejects signaling/non-canonical NaNs) instead of silently rounding, with negative test coverage in test_narrow_float_values_rejects_lossy_and_non_canonical_nan.
  2. Simplified FloatWidenScheme: Removed CachedFullWiden, CachedBestTarget, and the finished_cascading special-case branch, keeping only NarrowestFloatTarget so the full array is scanned at most once.
  3. Conformance + Hegel + test cleanup: Added a nullable float fixture (-0.0, None, 1.5, ±inf, NaN) to test_conformance, added a Hegel property test (test_encode_float_hegel_bit_exact_and_ops) covering encode_float bit-exactness, target selection, and check_encoding_roundtrip_and_ops, and trimmed the redundant unit tests (test_encode_float_f64_bit_exact_round_trip, test_float_filter_mask_slice_take, and the large constant matrix in test_compare_f32_widen_to_f64_constants) while keeping targeted NaN/pushdown-decline/cast/serde coverage.
  4. Widen::take perf note: The indices.len() > array.len() guard already avoids decoding Dict(codes, Widen(values)) via Widen::take (verified by test_dict_take_widens_small_values_table_once and the earlier +44.46% CodSpeed improvement on take_many_indices); happy to add a full benchmark table if needed.

devin-ai-integration[bot]

This comment was marked as resolved.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

CodSpeed Performance Analysis (8fd28d7 vs develop c6990e0):

  • encode_primitives[u8, (2000, 2)] (vortex-array/benches/dict_compress.rs, 92.5 µs -> 119.1 µs, -22.35%): Unrelated noise — this benchmark calls vortex_array::builders::dict::dict_encode on a PrimitiveArray<u8>. None of the files modified in this PR (vortex-array/src/arrays/widen/*, vortex-btrblocks, vortex-compressor, vortex-cuda/.../widen, vortex-functions/src/zip/widen.rs) are on its code path (similar to varbinview_large simultaneously showing +13.16% with no listview/varbinview changes).
  • take_many_indices (vortex-array/benches/widen.rs, 618.7 µs -> 429.3 µs, +44.14%): The one benchmark touching this PR's code improved.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Gemini 4 Carbon on behalf of @lwwmanning.

The bit-exact IEEE-754 narrowing semantics (-0.0, subnormals, canonical positive quiet NaN, and null-slot zeroing) and the preview2026.11.0 compressor gating look good. Three substantive issues need to be addressed before landing:

  1. BetweenReduce double-decodes float Widen on non-exact constant bounds (vortex-functions/src/between/widen.rs):
    • BetweenReduce for Widen assumes Widen::compare handles every Constant operand without decoding (let is_operand = |bound| bound.is::<Constant>() || bound.is::<Widen>()). That invariant does not hold for float Widen: compare_float_constant returns Ok(None) for any constant not bit-exactly representable in values_ptype (such as 0.1_f64 over narrowed f16/f32 values) and for NaN bounds. As a result, Between(float_widen, Constant(0.1_f64), Constant(0.9_f64)) rewrites to as_two_compares(...), which falls back and decodes the canonical f64 array twice instead of returning Ok(None) so Between decodes once (violating the invariant documented at vortex-functions/src/between/widen.rs:40).
    • Conversely, when both bounds are exact non-NaN constants in values_ptype (e.g., 0.0_f64 and 1.0_f64), constant_fits_values returns None for floats and misses the single-pass widen.values().between(narrow_lower, narrow_upper, ...) fast path.
  2. Compile break against develop (vortex-array/src/arrays/widen/compute/compare.rs):
    • develop (#12196) added a third CompareMode parameter to ArrayBuiltins::compare. Because compare_float_constant is a newly added function calling 2-argument values.compare(constant, operator), Git marks the PR MERGEABLE while merging into develop will fail to compile. Rebasing will also refresh CodSpeed against develop to clear the unrelated encode_primitives[u8, (2000, 2)] failure.
  3. Test bloat (>100 added cases vs AGENTS.md's <= 20 bound), shared-oracle Hegel property, and STYLE.md bitmap loops:
    • vortex-array/src/arrays/widen/tests/float.rs alone is 827 lines and monomorphizes ~75 test cases (7 #[rstest] expanding 65 #[case]s + 9 #[test] + 1 #[hegel::test]), pushing the PR past 100 added test cases.
    • test_encode_float_hegel_bit_exact_and_ops (tests/float.rs:277-285) computes expected target width by calling super::super::encode::f64_fits_in_f16 / f64_fits_in_f32—the encoder's own internal helpers—and only draws PType::F64 (never PType::F32), so a bug in f64_fits_in_* would agree with itself.
    • tests/float.rs:277-278,294, vortex-btrblocks/src/schemes/float/widen.rs:327, and vortex-functions/src/zip/widen.rs:290 call mask.value(i) inside per-element 0..len loops (STYLE.md hidden-cost accessor table).

(Note on preview2026.11.0: reusing vortex.widen metadata tag 1 without a new ArrayId requires preview2026.11.0 to freeze with min_library_version >= 0.96.0, since 0.94.0/0.95.0 shipped preview2026.11.0 without float Widen deserialization.)

Remediation Plan

  1. Rebase onto origin/develop and thread CompareMode:
    • In vortex-array/src/arrays/widen/compute/compare.rs, pass CompareMode through compare_float_constant to values.compare(constant, operator, mode) and verify parity against canonical execution under both CompareMode::TOTAL_ORDER and CompareMode::IEEE (including -0.0 vs +0.0 and quiet NaN).
  2. Update BetweenReduce for Widen in vortex-functions/src/between/widen.rs:
    • Extend constant_fits_values / constant_in_values_dtype to narrow non-NaN, bit-exactly representable float constants so exact constant bounds push down to values.between(lower, upper, options.clone()) in one pass.
    • Tighten is_operand for float Widen so as_two_compares is only used when both bounds can actually execute in Widen::compare without decoding (exact non-NaN float Constant or Widen); otherwise return Ok(None) so Between decodes widen once. Add a test covering both exact and non-exact/NaN float bounds.
  3. Make the Hegel oracle independent, collapse #[rstest] matrices to <= 20 added test cases, and remove mask.value(i) loops:
    • In vortex-array/src/arrays/widen/tests/float.rs, replace f64_fits_in_f16/f64_fits_in_f32 in test_encode_float_hegel_bit_exact_and_ops with an independent inline IEEE bit-roundtrip + canonical-qNaN check, draw both PType::F32 and PType::F64, and include between checks.
    • Collapse the single-value #[rstest] expansions across tests/float.rs, tests/serde.rs, vortex-btrblocks/src/schemes/float/widen.rs, and vortex-functions/src/zip/widen.rs into table loops inside <= 15–18 focused test functions total (renaming test_compare_f16_widen_constants_and_constant_folding to remove the stale constant-folding reference), and replace mask.value(i) loops with mask.to_bit_buffer() / for_each_set_index.

- Pass CompareMode::TOTAL_ORDER in compare_float_constant and verify
  float Widen comparisons against canonical under TotalOrder,
  ZerosEqual, Canonical, and Ieee754 modes.
- Extend constant_fits_values for non-NaN bit-exact floats so
  BetweenReduce pushes exact bounds to values.between(...) in one pass
  and declines on non-exact or NaN float bounds to avoid double decoding.
- Use an independent IEEE bit-roundtrip + canonical-qNaN oracle in
  test_encode_float_hegel_bit_exact_and_ops, draw both F32 and F64,
  replace mask.value(i) loops with for_each_set_index, and collapse
  added test cases to 18 (<= 20).

Co-Authored-By: Antigravity <noreply@google.com>
Signed-off-by: Will Manning <will@willmanning.io>
devin-ai-integration[bot]

This comment was marked as resolved.

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of 1b8af79. The roborev PR comment has the full review.

Comment on lines +218 to +241
.execute_mask(primitive.len(), exec_ctx)?;
let Some(narrowest) = data
.get_or_insert_with(|| NarrowestFloatTarget(narrowest_float_ptype(&primitive, &mask)))
.0
else {
return Ok(data.array().clone());
};

let candidates = candidate_targets(primitive.ptype(), narrowest);
compress_with_candidates(
compressor,
&primitive,
&mask,
candidates,
compress_ctx,
exec_ctx,
)
}
}

#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::sync::LazyLock;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: FloatWidenScheme::compress narrows and cascade-compresses an f16-fitting f64 column twice. candidate_targets returns [F16, F32], and compress_with_candidates runs compress_encoded for each. The estimate callback has already chosen a winner on the sample, but only NarrowestFloatTarget is cached. compress does not reuse that winner.

Fix: Cache the target that wins on the sample in the estimate callback and have compress use only that target, trying both candidates only when nothing is cached. Output stays bit-exact.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Re: roborev (1b8af79) on FloatWidenScheme::compress: intentionally leaving CachedBestTarget out per review 6100568199 — keeping only NarrowestFloatTarget avoids an extra cache slot and lets compress pick cleanly between F16 and F32 on the full column (including when an out-of-sample f32 outlier disqualifies F16).

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I checked 1b8af79. The CompareMode, BetweenReduce and Hegel-oracle fixes are correct. A float constant that does not fit can no longer reach compare_out_of_range, because floats branch to compare_float_constant first.

The test change does not reduce the tests. Added test code grew from 1,420 to 1,680 lines (tests/float.rs from 827 to 938). The #[rstest] cases became loops inside merged functions such as compresses_narrow_targets_and_skips_unnarrowable and wire_round_trip_and_child_policy. Coverage is the same, and a failure no longer names its case. The AGENTS.md limit asks for fewer cases, not fewer test attributes.

The Hegel property now has an independent oracle. With check_encoding_roundtrip_and_ops, it covers the bit-exact round trip and the operations. Please delete the hand-picked cases that the property already covers. Keep separate tests for the contracts it cannot reach: NaN and signaling-NaN rejection, the declining constants, the cast rules and the serde cases.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed in 3e28425c6 (-380 net test lines across the 4 files):

  • Deleted the hand-picked f16/f32/f64 selection and constant-matrix cases already covered by test_encode_float_hegel_bit_exact_and_ops + check_encoding_roundtrip_and_ops (tests/float.rs: 938 → 755 lines), keeping separate named tests for the contracts Hegel cannot reliably reach: test_float_nan_and_snan_rejection, test_float_compare_pushdown_and_decline, test_float_cast_rules, test_float_fill_null, test_float_numeric_declines_and_preserves_f64_precision, test_float_aggregates_match_canonical_and_sum_declines, test_float_try_new_and_flatten, and test_float_execute_encoded_dict_child.
  • Removed the duplicated test_float_widen_wire_serde from tests/serde.rs and folded the float round-trip and invalid-metadata checks into the existing #[rstest] cases (+18 lines total).
  • Split the merged FloatWidenScheme tests back into 4 small named tests (compresses_f32_and_f16_exact_columns, skips_unnarrowable_and_ignores_null_garbage, does_not_crowd_out_better_schemes_on_uniform_or_null_samples, honors_child_policy) and dropped the redundant wire round-trip copy.
  • Trimmed test_float_between_pushdown_and_decline in vortex-functions/src/between/widen.rs while exercising f32 -> f64 as the value column.

devin-ai-integration[bot]

This comment was marked as resolved.

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of 3e28425. The roborev PR comment has the full review.

Comment on lines +218 to +240
.execute_mask(primitive.len(), exec_ctx)?;
let Some(narrowest) = data
.get_or_insert_with(|| NarrowestFloatTarget(narrowest_float_ptype(&primitive, &mask)))
.0
else {
return Ok(data.array().clone());
};

let candidates = candidate_targets(primitive.ptype(), narrowest);
compress_with_candidates(
compressor,
&primitive,
&mask,
candidates,
compress_ctx,
exec_ctx,
)
}
}

#[cfg(test)]
mod tests {
use std::sync::Arc;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: For an f64 column that fits f16 exactly, compress runs full child compression twice, once for each target in [F16, F32]. The estimate callback already compares both candidates, on the sample or on the whole array when the array is too small to sample. It caches only NarrowestFloatTarget and not the winner, so compress repeats that work. This roughly doubles write-time cost for these columns.

Fix: Cache the winning target from the estimate callback in ArrayAndStats and have compress use only that target, trying both candidates only when nothing is cached.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posted by Claude Opus 5.5 on Will's behalf.

I checked 3e28425. The deletions match the request, and the Hegel property covers the hand-picked selection cases. The serialized bytes did not change, and the [8, 9] and [8, 8] metadata cases are still pinned. Two contract cases went out with the trim.

  1. No hand-written test now compares an f16 child with a constant. So nothing checks that the (F64, F16) and (F32, F16) arms of constant_fits_values (compute/mod.rs lines 149 and 150) decline. The Hegel compare takes its pivot from the array, so its constants always fit. For example, suppose the (F64, F16) arm called f64_fits_in_f32 by mistake. A compare of the f16 value 0.0999755859375 with f64::from(0.1_f32) would then push down, and Lt would return false instead of true. One f16 to f64 fixture in test_float_compare_pushdown_and_decline would cover this, with constants such as 0.1, f64::from(0.1_f32) and f64::from(f16::MAX).next_up().

  2. No test now rejects a float child as wide as its parent. The trim removed the equal-width rows from test_float_try_new_and_flatten and the (F64, [8, 10]) serde case. The remaining F64 under F32 case still fails if the check at array.rs line 80 becomes <=. With that change, a reader would accept vortex.widen metadata [8, 10] under an f64 parent. One case in test_widen_wire_rejects_invalid_child_metadata restores the check: #[case::float_same_width(PType::F64.into(), &[8, 10], "narrower")].

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Restored both contract cases in 38476e356:

  1. Added f16 -> f64 (0.1_f64, f64::from(0.1_f32), f16::MAX.to_f64().next_up(), f64::NAN) and f16 -> f32 (0.1_f32, f16::MAX.to_f32().next_up(), f32::NAN) pushdown/decline checks in test_float_compare_pushdown_and_decline so both (F64, F16) and (F32, F16) arms of constant_fits_values are exercised.
  2. Restored the equal-width float rejection in test_float_try_new_and_flatten and added #[case::float_same_width(PType::F64.into(), &[8, 10], "narrower")] to test_widen_wire_rejects_invalid_child_metadata.

@vortex-roborev-bot vortex-roborev-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line comments for the roborev review of 38476e3. The roborev PR comment has the full review.

Comment on lines +208 to +235
fn compress(
&self,
compressor: &CascadingCompressor,
data: &ArrayAndStats,
compress_ctx: CompressorContext,
exec_ctx: &mut ExecutionCtx,
) -> VortexResult<ArrayRef> {
let primitive = data.array_as_primitive().into_owned();
let mask = primitive
.validity()?
.execute_mask(primitive.len(), exec_ctx)?;
let Some(narrowest) = data
.get_or_insert_with(|| NarrowestFloatTarget(narrowest_float_ptype(&primitive, &mask)))
.0
else {
return Ok(data.array().clone());
};

let candidates = candidate_targets(primitive.ptype(), narrowest);
compress_with_candidates(
compressor,
&primitive,
&mask,
candidates,
compress_ctx,
exec_ctx,
)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low: FloatWidenScheme::compress runs the full compress_encoded cascade for both F16 and F32 when an f64 column fits f16. The estimate callback has already compared these candidates, but it caches only NarrowestFloatTarget and not which candidate won. As a result, compress_with_candidates repeats the work on the full array. For these columns, compression at write time costs about twice as much.

Fix: Cache the winning candidate's ptype from the estimate callback in ArrayAndStats and have compress narrow only to that target, falling back to trying both candidates only when no winner is cached.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Issue: Lossless float Widen and FloatWidenScheme

2 participants